package com.tianfang.mytranmqproducer.service;

import com.alibaba.fastjson.JSONObject;
import com.tianfang.mytranmqproducer.common.params.MailParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * Created by TT on 2018-05-31.
 */
@Service
public class MQProducerService{
    @Value("${spring.activemq.queue.name}")
    private String queueName;
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * 发送消息.
     * @param mail
     */
    public void sendMessage(final MailParam mail) {
        jmsMessagingTemplate.convertAndSend(queueName,JSONObject.toJSONString(mail));
    }
}
